/*
Web: http://www.jsForms.com
Copyright (C) 2008  Igor Demyanov (mailto:Igor.Demyanov@gmail.com)
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
jsForms.Components.Window={
	Init:function()
	{
		this.P.isInit = true;
		this.Draggable(this.P.Draggable).Resizable(this.P.Resizable);
		this.C.close.bind('click',this,this.eventCloseClick);
		return jsForms.Components.Component.Init.call(this);
	},
	eventCloseClick : function(e)
	{
		if (e.data) {
			e.data._ExecEvent.call(e.data,'onClose',e.data);
		}
	},
	Draggable:function(flag)
	{
		/*if (this.P.Draggable == flag)
		{
			return this;
		}*/
		this.P.Draggable = (flag=="true"||flag==true);
		if (this.P.isInit !=true) 
		{
			return this;
		}
		if (this.P.Draggable == true) {
			if (this.P.DraggableInit == true) {
				this.draggable("enable");
			}
			else
			{
				this.P.DraggableInit = true;
				this.draggable({
				handle: this.C.header,
				containment: 'parent'});
			}
		}else
		if (this.P.DraggableInit == true) 
		{
			this.draggable("disable");
		}
		return this;
	},
	Resizable:function(flag)
	{
		/*if (this.P.Resizable == flag)
		{
			return this;
		}*/
		this.P.Resizable = (flag=="true"||flag==true);
		if (this.P.isInit!=true) 
		{
			return this;
		}
		if (this.P.Resizable == true) {
			if (this.P.ResizableInit == true) {
				this.resizable("enable");
			}
			else
			{
				this.P.ResizableInit = true;
				this.resizable({
				transparent: false,
				helper: 'proxy',
				containment: 'parent',
				zIndex: '9999999',
				minWidth: 100,
				minHeight: 100,
				handles: 'se'});
			}
		}else
		if (this.P.ResizableInit == true)
		{
			this.resizable("disable");
		}
		return this;
	},
	SetTitle:function(title)
	{
		if (this.P.Title != title) {
			this.P.Title = title;
			this.C.header.text(title);
		}
		return this;
	}
};

jsForms.CreateCompileInfoByObject(
{
	Name: 'Window',
	Properties: {
		Title: {
			Type: 'String',
			Access: 'GETSET'
		},
		Draggable:{
			Type:'boolean',
			Access:'direct'
		},
		Resizable:{
			Type:'boolean',
			Access:'direct'
		}
	},
	Events: {
		onClose:{}
	},
	Contents:
	{
		content:{}
	}
});
